<template>
  <article class="page">
    <headerbar>培训班
      <!--<span @click="showMenu" class="head-btn-text" slot="btn">更多</span>-->
    </headerbar>
    <div class="nav-wrap">
      <cube-scroll-nav-bar :current="current" :labels="labels" @change="changeHandler"/>
    </div>
    <section class="frame-content-sub no-bg" v-if="data && '基本信息'==current">
      <section class="inner-content pdv-9 pdh-4 inner-noborder">

        <div class="input-column-wrap">
          <div class="name">培训计划名称：</div>
          <div class="text-left input-value color-tip">{{data.trainingclass}}</div>
        </div>
        <div class="input-column-wrap">
          <div class="name">办班单位：</div>
          <div class="text-left input-value color-tip">{{data.deptname}}</div>
        </div>
        <div class="input-column-wrap">
          <div class="name">机构名称：</div>
          <div class="text-left input-value color-tip">{{data.institutionsName}}</div>
        </div>

        <div class="input-column-wrap">
          <div class="name">培训期数：</div>
          <div class="text-left input-value color-tip">{{data.numberofperiods}}</div>
        </div>
        <div class="input-column-wrap">
          <div class="name">培训地点：</div>
          <div class="text-left input-value color-tip">{{data.place}}</div>
        </div>

        <div v-if="data.type === '1' && checkFlag" @click="agreeAlert()" class="default-block-btn mgh-10">同意</div>
        <div v-if="data.type === '1' && checkFlag" @click="alert()" class="default-block-btn mgh-10">不同意</div>
        <div v-if="data.type === '5' && data.zjspzt === '0' && checkFlag" @click="zjshAgreeAlert()" class="default-block-btn mgh-10">总结审核同意</div>
        <div v-if="data.type === '5' && data.zjspzt === '0' && checkFlag" @click="zjshAlert()" class="default-block-btn mgh-10">总结审核不同意</div>
      </section>
    </section>
    <!--教学计划-->
    <section class="block " v-if="data.curriculumList && '教学计划'==current">
      <div class="pdv-3 list-news-img list-wenda mgh-2">
        <div v-for="(item,index) in data.curriculumList" :key="index" class="item">
          <div class="cont  pdh-0">
            <div class="title">{{index+1}}、课程名称：{{item.name}}</div>
            <div class="">
              <p class="tip">讲师：{{item.lecturerName}} <i class="pdh-2"></i>  班级名称：{{item.className}}</p>
              <p class="tip">模块：{{item.modular}}  <i class="pdh-2"></i> 学时：{{item.classHour}} </p>
              <p class="tip">培训时间：{{item.beginData}} - {{item.endData}}</p>
            </div>
          </div>

        </div>
      </div>
    </section>
    <!--学员名单-->
    <section class=" pdv-3 " v-if="data.userContactList && '学员名单'==current">
      <section class="people-list ">

        <div class="people-item bg-white block" v-for="item in data.userContactList">
          <section class="people-info">
            <span class="name">{{item.userName}}</span>
            <span class="name">{{item.score}}</span>
          </section>
          <span class="">
            </span>
        </div>
      </section>
    </section>
  </article>
</template>

<script>
  import _ from 'lodash'
  export default {
    data () {
      return {
        data: {},
        form: {},
        userInfo: this.$store.state.userInfo,
        current: '基本信息',
        labels: [
          '基本信息',
          '教学计划',
          '学员名单'
        ],
        checkFlag: false
      }
    },
    created () {
      this.id = this.$route.query.id
      if (this.userInfo && this.userInfo.permissions) {
        if (this.userInfo.permissions.indexOf('planInfo:post/trainingplanClass/sp') > -1) {
          this.checkFlag = true
        }
      }
      this.loadData(this.id)
    },
    methods: {
      changeHandler (cur) {
        this.current = cur
      },
      check (type, checkOpinion, flag) {
        // 计划状态：0计划填报、1计划审核中、2计划审核通过、3计划审核不通过、、4计划取消审核中、5计划取消审核通过、6计划取消审核不通过，1变成2,3；4变成5,6
        let query = this.$route.query
        let params = {
          id: query.id,
          type: type
        }
        if (flag === 1) {
          params.zjspzt = '1'
        } else if (flag === 2) {
          params.zjspzt = '2'
        }
        this.fetchService.trainingplanClassSave(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          this.addPlanLog(query.id, checkOpinion, type, flag)
          this.loadData(query.id)
        })
      },
      addPlanLog (id, spyj, type, flag) {
        if (type === '2' || flag === 1) {
          spyj = '同意'
        } else {
          spyj = '不同意'
        }
        let params = {
          pxjhId: id,
          spyj: spyj,
          spr: this.userInfo.id,
          sprxm: this.userInfo.nickname,
          classId: this.id
        }
        if (type === -1) {
          params.hjmc = '培训班审核'
        } else {
          params.hjmc = '培训班总结审核'
        }
        this.fetchService.trainingplanInfoLogSaveOrUpdateOfAll(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          this.tools.alert('操作成功')
        })
      },
      loadData (id) {
        let params = {
          'id': id
        }
        this.fetchService.trainingplanClassSelectAll(params).then(res => {
          if (res.code !== 0) {
            return this.tools.alert(res.message || res.resp_msg)
          }
          this.isLoading = false
          this.data = res.data
        })
      },
      agreeAlert () {
        this.dialog = this.$createDialog({
          type: 'prompt',
          title: '审核',
          prompt: {
            value: '',
            placeholder: '请输入审核意见'
          },
          onConfirm: (e, promptValue) => {
            this.check('2', promptValue, -1)
          }
        }).show()
      },
      alert () {
        this.dialog = this.$createDialog({
          type: 'prompt',
          title: '审核',
          prompt: {
            value: '',
            placeholder: '请输入审核意见'
          },
          onConfirm: (e, promptValue) => {
            this.check('3', promptValue, -1)
          }
        }).show()
      },
      zjshAgreeAlert () {
        this.dialog = this.$createDialog({
          type: 'prompt',
          title: '审核',
          prompt: {
            value: '',
            placeholder: '请输入审核意见'
          },
          onConfirm: (e, promptValue) => {
            this.check('5', promptValue, 1)
          }
        }).show()
      },
      zjshAlert () {
        this.dialog = this.$createDialog({
          type: 'prompt',
          title: '审核',
          prompt: {
            value: '',
            placeholder: '请输入审核意见'
          },
          onConfirm: (e, promptValue) => {
            this.check('5', promptValue, 2)
          }
        }).show()
      }
    }
  }
</script>

<style scoped lang="scss">
  @import "@/common/stylus/moon.scss";
  .tip {
    font-size:$defaultFontSize;
  }
</style>
